package com.shigu.main4.common.util;

import java.math.BigDecimal;
import java.text.DecimalFormat;

/**
 * Created by pc on 2015-12-26.
 */
public class MoneyUtil {
    /**
     * 处理费率
     * @param rate
     * @return
     */
    public static String dealRate(String rate){
        Double r=Double.valueOf(rate)*100;
        DecimalFormat df=new DecimalFormat("0.00");
        return df.format(r)+"%";
    }

    public static String dealRate4(Double rate){
        DecimalFormat df=new DecimalFormat("0.0000");
        return df.format(rate);
    }

    public static String dealPrice(Long price){
        String gewei="";
        if(Math.abs((price%100))<10){
            gewei+="0"+ Math.abs((price%100));
        }else{
            gewei+= Math.abs((price%100));
        }
        return (price/100)+"."+gewei;
    }

    public static Long StringToLong(String price){
        BigDecimal mon = new BigDecimal(price);
        BigDecimal mon100 = new BigDecimal("100");
        return mon.multiply(mon100).longValue();

    }

    public static String formatMoney(String money){
        return formatMoney(Double.valueOf(money));
    }

    public static String formatMoney(Double money){
        DecimalFormat df=new DecimalFormat("0.00");
        return df.format(money);
    }

    public static Double formatMoneyDouble(Double money){
        DecimalFormat df=new DecimalFormat("0.00");
        return Double.valueOf(df.format(money));
    }

    public static Double formatMoneyDouble(String money){
        return formatMoneyDouble(Double.valueOf(money));
    }

    public static void main(String[] args) {

        System.out.println(StringToLong("4.15"));


    }


}
